import Taro from '@/newTaro'


/**
 * 返回屏幕可用宽高度
 * // NOTE 各端返回的 windowHeight 不一定是最终可用高度（例如可能没减去 statusBar 的高度），需二次计算
 * @param {*} showTabBar，当前页面是否是tab页
 */
 export function getWindowWH(showTabBar = true) {
    const NAVIGATOR_HEIGHT = 44
    const TAB_BAR_HEIGHT = 50
    const info = Taro.getSystemInfoSync()
    const { windowHeight, statusBarHeight, titleBarHeight,windowWidth } = info
    
    let height=windowHeight;
    
    if (process.env.TARO_ENV === 'rn') {
      height=windowHeight - statusBarHeight - NAVIGATOR_HEIGHT - (showTabBar ? TAB_BAR_HEIGHT : 0)
    }
  
    if (process.env.TARO_ENV === 'h5') {
        height=windowHeight - (showTabBar ? TAB_BAR_HEIGHT : 0)
    }
  
    if (process.env.TARO_ENV === 'alipay') {
       height=windowHeight - statusBarHeight - titleBarHeight + (showTabBar ? 0 : TAB_BAR_HEIGHT)
    }
    
    if (process.env.TARO_ENV === 'weapp') {
      height=windowHeight - NAVIGATOR_HEIGHT - (showTabBar ? TAB_BAR_HEIGHT : 0)
    }
  
    return {width:windowWidth,height:height}
  }
  